//
//  StatusCellTopView.swift
//  weibo10
//
//  Created by 晁岳山 on 15/10/19.
//  Copyright © 2015年 晁岳山. All rights reserved.
//

import UIKit
import SDWebImage
class StatusCellTopView: UIView {
    //对控件进行设值
    var viewModel: StatusViewModel? {
        didSet {
            //1.头像
            iconImageView.sd_setImageWithURL(viewModel?.userProfileURL, placeholderImage: UIImage(named: "avatar_default_big"))
            //2.名字
            nameLabel.text = viewModel?.status.user?.screen_name
            //3.等级
            menberImageView.image = viewModel?.userMenberImage
            //4.vip标识
            vipImageView.image = viewModel?.userVerifiedTypeImage
            //5.发送微博的时间
            timeLabel.text = "刚刚"
            //6.发送微博的出处
            sentLabel.text = "小晁同学"
        }
    }
    //构造方法
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //懒加载需要的控件
    //0.顶部视图
    private lazy var topView: UIView = UIView()
    //1.头像
    private lazy var iconImageView: UIImageView = UIImageView(image: UIImage(named: "avatar_default_big"))
    //2.名字
    private lazy var nameLabel: UILabel = UILabel(content: "天空飘来五个字")
    //3.等级
    private lazy var menberImageView: UIImageView = UIImageView(image: UIImage(named: "common_icon_membership_level2"))
    //4.vip标识
    private lazy var vipImageView: UIImageView = UIImageView(image: UIImage(named: "avatar_vip"))
    //5.发送微博的时间
    private lazy var timeLabel: UILabel = UILabel(content: "刚刚", fontSize: 12, color: UIColor.orangeColor())
    //6.发送微博的出处
    private lazy var sentLabel: UILabel = UILabel(content: "小炒微博", fontSize: 13)
}

// 设置控件的布局
extension StatusCellTopView {
    //设置布局
    private func setupUI() {
        topView.backgroundColor = UIColor(white: 0.9, alpha: 1.0)
        addSubview(topView)
        addSubview(iconImageView)
        addSubview(nameLabel)
        addSubview(menberImageView)
        addSubview(vipImageView)
        addSubview(timeLabel)
        addSubview(sentLabel)
        //添加约束
        //0.顶部视图
        topView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left)
            make.top.equalTo(self.snp_top)
            make.width.equalTo(self.snp_width)
            make.height.equalTo(StatusCellMargin)
        }
        //1.头像
        iconImageView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left).offset(StatusCellMargin)
            make.top.equalTo(topView.snp_bottom).offset(StatusCellMargin)
            make.width.equalTo(StatusCellWidth)
            make.height.equalTo(StatusCellWidth)
        }
        //2.名字
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(iconImageView.snp_right).offset(StatusCellMargin)
            make.top.equalTo(iconImageView.snp_top)
        }
        //3.等级
        menberImageView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(nameLabel.snp_right).offset(StatusCellMargin)
            make.top.equalTo(nameLabel.snp_top)
        }
        //4.vip标识
        vipImageView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconImageView.snp_right)
            make.centerY.equalTo(iconImageView.snp_bottom)
        }
        //5.发送微博的时间
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(iconImageView.snp_right).offset(StatusCellMargin)
            make.bottom.equalTo(iconImageView.snp_bottom)

        }
        //6.发送微博的出处
        sentLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(timeLabel.snp_right).offset(StatusCellMargin)
            make.bottom.equalTo(iconImageView.snp_bottom)
        }
    }
    
}